<?php


namespace RedMVC\Form\Validator;

/**
 * Numeric class
 *  
 * @category    RedMVC
 * @package     Form
 * @subpackage  Validator 
 * @author      Jan Fischer, bitWorking <info@bitworking.de>
 */
class Numeric extends AValidator{

    protected $_min;
    protected $_max;
    
    public function __construct($min = null, $max = null){
        $this->_min = $min;
        $this->_max = $max;
    }

    public function isValid($value, $formValues = null){        
        if(!is_numeric($value)){
            $this->setError('FORM_VALIDATOR_NUMERIC');
            return false;
        }
        if(($this->_min !== null)&&($value < $this->_min)){
            $this->setError('FORM_VALIDATOR_NUMERIC_MIN', $this->_min);
            return false;
        }
        if(($this->_max !== null)&&($value > $this->_max)){
            $this->setError('FORM_VALIDATOR_NUMERIC_MAX', $this->_max);
            return false;
        }        
        return true;
    }
}